//
//  DestinationVC.m
//  ImGuider
//
//  Created by 李陆涛 on 2017/12/11.
//  Copyright © 2017年 imguider. All rights reserved.
//

#import "DestinationVC.h"
#import "DestinationCell.h"
#import "CityVC.h"

@interface DestinationVC ()<UITableViewDelegate, UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) NSArray *dataSource;
@end

@implementation DestinationVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self setupUI];
}

- (void)setupUI {
    [self setAutoRowHeight:self.tableView];
    [self registCells:@[@"DestinationCell"] tableView:self.tableView];
    

    [NetAPIManager getMoreCitysWithBlock:^(NSArray<City *> *citiesArray, NSError *error) {
        
        self.dataSource = citiesArray;
        [self.tableView reloadData];
    }];
}



- (void)scanAction {
    
    
}

#pragma mark - Table view data source

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.dataSource.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    City *city = self.dataSource[indexPath.row];
    
    DestinationCell *cell = [tableView dequeueReusableCellWithIdentifier:@"DestinationCell"];
    cell.city = city;
    
    return cell;
}


#pragma mark - Table view delegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    City *city = self.dataSource[indexPath.row];
    
    CityVC *cityVC = [CityVC new];
    cityVC.cid = city.cid.stringValue;
    
    [self.superVC.navigationController pushViewController:cityVC animated:YES];
}


//- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
//    
//    CGFloat viewHeight = scrollView.height + scrollView.contentInset.top;
//    
//    for (DestinationCell *cell in [self.tableView visibleCells]) {
//        CGFloat y = cell.centerY - scrollView.contentOffset.y;
//        CGFloat p = y - viewHeight / 2;
//        CGFloat scale = cos(p / viewHeight * 0.8) * 0.95;
//        
//        [UIView animateWithDuration:0.15 delay:0 options:UIViewAnimationOptionCurveEaseInOut | UIViewAnimationOptionAllowUserInteraction | UIViewAnimationOptionBeginFromCurrentState animations:^{
//            cell.destinationImageView.transform = CGAffineTransformMakeScale(scale, scale);
//        } completion:NULL];
//    }
//}

@end
